package com.projectnection.server.database.entities;

import java.util.List;

import com.google.appengine.repackaged.org.json.JSONArray;
import com.googlecode.objectify.Objectify;
import com.projectnection.server.database.ObjectifyServiceCreation;
import com.projectnection.server.model.Entity;

public class ListEntities {

	public static JSONArray jsonList() {

		return jsonList(list());
	}

	public static List<Entity> list() {

		Objectify objfyService = ObjectifyServiceCreation.gerService();

		List<Entity> entitiesList = objfyService.query(Entity.class)
				.order("entityName").list();

		return entitiesList;
	}

	public static JSONArray jsonList(List<Entity> entities) {

		JSONArray jsonEntities = new JSONArray();

		for (Entity entity : entities) {

			jsonEntities.put(GetEntity.jsonEntity(entity));
		}

		return jsonEntities;
	}

}